package com.swsc.solarverse.dao.mapper.analysis;

import com.swsc.solarverse.common.mybatis.BasePlusMapper;
import com.swsc.solarverse.dao.entity.analysis.StringEfficiencyRecordDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author AutoGenerator
 * @since 2024-06-04
 */
@Mapper
public interface StringEfficiencyRecordMapper extends BasePlusMapper<StringEfficiencyRecordDO> {

    @org.apache.ibatis.annotations.Insert(value = {
            "<script>",
            "INSERT IGNORE INTO solar_string_efficiency_record (`id`,`tenant_no`,`organ_no`,`device_pid`,`device_id`,`device_name`,`device_code`,`data_time`,`efficiency`,`submatrix_avg_e`, `submatrix_string_num`, `submatrix_string_valid_num`, `loss_e`, `submatrix`, `zone`, `create_time`) VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id}, #{item.tenantNo}, #{item.organNo}, #{item.devicePid}, #{item.deviceId}, #{item.deviceName}, #{item.deviceCode}, #{item.dataTime}, #{item.efficiency}, #{item.submatrixAvgE}, #{item.submatrixStringNum}, #{item.submatrixStringValidNum}, #{item.lossE}, #{item.submatrix}, #{item.zone}, #{item.createTime})",
            "</foreach>",
            "</script>"
    })
    int insertIgnoreBatch(java.util.List<StringEfficiencyRecordDO> list);

    @org.apache.ibatis.annotations.Select(value = {
            "<script>",
            "SELECT AVG(`loss_e`) loss_e ",
            " FROM `solar_string_efficiency_record` ",
            "<where>",
            "<if test='dataTimeGe != null'> AND `data_time` >= #{dataTimeGe}</if>",
            "<if test='dataTimeLt != null'> AND `data_time` &lt; #{dataTimeLt}</if>",
            "<if test='organNoIn != null and organNoIn.size() > 0'> AND `organ_no` IN ",
            "<foreach collection='organNoIn' item='organNo' open='(' close=')' separator=',' index=''>#{organNo}</foreach>",
            "</if>",
            "</where>",
            "</script>"
    })
    Double avgLossE(@Param("organNoIn") java.util.Collection<Integer> organNoIn, @Param("dataTimeGe")LocalDateTime dataTimeGe, @Param("dataTimeLt")LocalDateTime dataTimeLt);
    @org.apache.ibatis.annotations.Select(value = {
            "<script>",
            "SELECT SUM(loss_e) / sum(submatrix_string_num) AS LOSS_E",
            " FROM `solar_string_efficiency_record` ",
            "<where>",
            "<if test='dataTimeGe != null'> AND `data_time` >= #{dataTimeGe}</if>",
            "<if test='dataTimeLt != null'> AND `data_time` &lt; #{dataTimeLt}</if>",
            "<if test='organNoIn != null and organNoIn.size() > 0'> AND `organ_no` IN ",
            "<foreach collection='organNoIn' item='organNo' open='(' close=')' separator=',' index=''>#{organNo}</foreach>",
            "</if>",
            "<if test='lossThresholdE != null'> AND `loss_e` > #{lossThresholdE}</if>",
            "</where>",
            "</script>"
    })
    Double avgLossENew(@Param("organNoIn") java.util.Collection<Integer> organNoIn,
                       @Param("dataTimeGe")LocalDateTime dataTimeGe,
                       @Param("dataTimeLt")LocalDateTime dataTimeLt,
                       @Param("lossThresholdE") Double lossThresholdE);
    @org.apache.ibatis.annotations.Select(value = "SELECT MIN(`data_time`) data_time FROM `solar_string_efficiency_record` WHERE organ_no = #{organNo}")
    LocalDateTime minDataTime(@Param("organNo")Integer organNo);
    @org.apache.ibatis.annotations.Select(value = "SELECT MAX(`data_time`) data_time FROM `solar_string_efficiency_record` WHERE organ_no = #{organNo}")
    LocalDateTime maxDataTime(@Param("organNo")Integer organNo);
}
